<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery-3.6.0.js"></script>
    <style>
        div.box {
            width: 500px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <!-- 参考显示隐藏的练习案例，给淡入淡出的动画事件，制作一样的页面。注意，fadeTo方法的opacity的值，请用滑块元素来实现。 -->
    <form name="myform">
        <p>速度</p>
        <input type="radio" name="speed" value="slow"> slow
        <input type="radio" name="speed" value="normal"> normal
        <input type="radio" name="speed" value="fast"> fast
        <input type="number" name="time">ms
        <br>
        <p>动画效果</p>
        <input type="radio" name="easing" value="swing"> swing
        <input type="radio" name="easing" value="linear"> linear
        <br>
        <p>透明度</p>
        <input type="range" name="rge">
    </form>
    <p></p>
    <button data-type="fadeIn">显示</button>
    <button data-type="fadeOut">隐藏</button>
    <button data-type="fadeToggle">切换</button>
    <p></p>
    <div class="box"></div>
    <script>
        $('button').click(function () {
            let type = this.dataset.type;
            let elements = document.forms.myform.elements;
            console.log(elements.speed);
            console.log(elements.easing);
            let speed = elements.speed.value;
            let easing = elements.easing.value;
            //获取透明度的值
            let rge = elements.rge.value / 100;
            console.log(rge);
            let time = elements.time.value;
            if (speed != 'slow' && speed != 'normal' && speed != 'fast') {
                speed = time * 1000;
            }
            // $('div').fadeTo(speed,rge,easing)
            if (type === 'fadeIn') {
                $('div').fadeTo(speed, rge,easing)
            } else if (type === 'fadeOut') {
                $('div').fadeOut(speed, easing)
            } else {
                $('div').fadeToggle(speed, easing)
            }
        })
    </script>
</body>

</html>